Turns from angle from toward angle to by step degrees, the SHORT way round, and never overshoots - landing exactly on to once step would carry it past.
angle_approach(from, to, step) -> real| Name | Type |
|---|---|
from | real |
to | real |
step | real |
real
Turns from toward to by step degrees, the short way round the circle, and never overshoots - once step would carry it past to, this lands exactly on to instead. angle_approach is approach taught to turn around a circle instead of moving along a straight line: it wraps and picks the short way exactly like angle_diff, because it uses angle_diff to work out which way to turn.
target = instance_nearest(x, y, obj_doc_walker);
if (target != nothing) {
direction = angle_approach(direction, dir_to(x, y, target.x, target.y), 3);
}Turns this turret 3 degrees closer to facing its nearest target every frame, always the short way round, and stops turning the instant it's actually facing them instead of spinning past and having to correct back. dir_to already returns an angle in the same convention direction already uses, so nothing needs converting in between - direction = angle_approach(direction, dir_to(...), turn_speed) is the shape this exists for.
step is a magnitude, never signedWhich way to turn is worked out from from/to themselves (via angle_diff), the same way approach's own step is never signed either. A step of 0 makes no progress and returns from unchanged, unless from already equals to.
One angle_diff call plus a comparison - see that page for exactly what angle_diff itself costs.
approach (below), taught to turn around a circle instead of moving along a line - built on angle_diff (above), so it wraps and picks the short way the same way angle_diff does, including the same +180 tie-break when to is exactly opposite from. direction = angle_approach(direction, dir_to(...), turn_speed) is the shape this exists for: dir_to already returns an angle in this same convention, so nothing needs converting in between. step is a magnitude, never signed - a step of 0 makes no progress.